package com.mrogrape.notepad.activity.action.item;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;

import com.mrogrape.notepad.common.ViewUtils;
import com.mrogrape.notepad.data.ViewContext;
import com.mrogrape.notepad.ui.editor.TextEditor;


public class ReloadMenuItemAction extends AbstractAction{

	/** serialVersionUID */
	private static final long serialVersionUID = -1L;

	public ReloadMenuItemAction(){

		super.putValue(Action.NAME, "Reload File");
		super.putValue(Action.SHORT_DESCRIPTION, "Reload current file");
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {

		TextEditor editor = ViewContext.getMainFrame().getCurrentTextEditor();
		if(editor != null){

			if(editor.isContentModified()){
				int op = ViewUtils.showOkCancelDialog(editor, "存在未保存的更改", "当前文件存在未保存的更改，是否放弃这些更改并重新加载文件？");
				if(op == ViewUtils.CANCEL_OPTION){
					return;
				}
			}

			editor.loadFile();
		}
	}
}
